<template>
   <div class="registerbody">
    <div class="register">
      <div class="register_box" align="center">
        <h3 style="margin-top:-20px;">注册</h3>
        <el-form
          :model="registerForm"
          :rules="registerRules"
          ref="registerForm"
          label-width="0px"
        >
          <el-form-item
            label=""
            prop="name"
            style="margin-top:-2px;"
          >
          <el-row>
              <el-col :span='2'>
                <span class="el-icon-user"></span>
              </el-col>
              <el-col :span='22'>
                <el-input 
                  class="inps"
                  placeholder='用户名'
                  v-model="registerForm.name">
                </el-input>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item
            label=""
            prop="name"
            style="margin-top:-20px;"
          >
            <el-row>
              <el-col :span='2'>
                <span class="el-icon-user-solid"></span>
              </el-col>
              <el-col :span='22'>
                <el-input 
                  class="inps"
                  placeholder='账号'
                  v-model="registerForm.userName">
                </el-input>
              </el-col>
            </el-row>
          </el-form-item>
           <el-form-item
            label=""
            prop="phone"
            style="margin-top:-20px;"
          >
            <el-row>
              <el-col :span='2'>
                <span class="el-icon-phone"></span>
              </el-col>
              <el-col :span='22'>
                <el-input 
                  class="inps"
                  placeholder='手机号'
                  v-model="registerForm.phone">
                </el-input>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item
            label=""
            prop="password"
             style="margin-top:-20px;"
          >
            <el-row>
              <el-col :span='2'>
                <span class="el-icon-lock"></span>
              </el-col>
              <el-col :span='22'>
                <el-input
                  class="inps"
                  type="password"
                  placeholder='密码'
                  v-model="registerForm.password"
                ></el-input>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item
            label=""
            prop="confirm"
            style="margin-top:-20px;"
          >
            <el-row>
              <el-col :span='2'>
                <span class="el-icon-lock"></span>
              </el-col>
              <el-col :span='22'>
                <el-input 
                  class="inps"
                  placeholder='再次确认密码'
                  v-model="registerForm.confirm">
                </el-input>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item style="margin-top:0px;">
            <el-button
              type="primary"
              round
              style="width:120px;"
              class="submit"
              @click="register"
            >注册
            </el-button>
            <el-button
              type="primary"
              round
              style="width:120px;"
              class="submit"
              @click="returnbtn"
            >返回
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
 
  export default {
    name: "register",
    data: function () {
      return {
        registerForm: {
          name: '',
          userName:'',
          phone: '',
          password: '',
          confirm: ''
        },
        registerRules: {
          name: [
            {required: true, message: "请输入账号", trigger: "blur"}
          ],
          userName:[
            {required: true, message: "请输入账号", trigger: "blur"}
          ],
          password: [{required: true, message: "请输入密码", trigger: "blur"}],
           phone: [
            {required: true, message: "请输入手机号", trigger: "blur"}
          ],
            confirm: [
            {required: true, message: "请输入相同密码", trigger: "blur"}
          ],
        },
         
      }
    },
   
    methods: {
         register() {
      if (this.registerForm.password != null && this.registerForm.userName != null) {
        if (this.registerForm.password == this.registerForm.confirm) {
          this.$axios.post("/api/user/register", this.registerForm).then((res) => {
            if(res.data.code==1){
            window.history.go(-1);
            alert("注册成功!")
            }
            else{
              alert("该账号已被注册!")
            }
          });
        } else {
          this.registerForm = {};
          alert("请确认密码！");
        }
      }
      else{
      alert("用户名或者密码不能为空");
      }
    },
    returnbtn(){
      window.location.href="http://localhost:8081/home#/"
    }
    }
  }
</script>

<style>
.registerbody {
    overflow: scroll;
    overflow-y: hidden;
    overflow-x: hidden;
  }
 
  .register {
    width: 100%;
    height: 100vh;
    font-size: 19px;
    background-position: left top;
    color: whitesmoke;
    position: relative;
    background-image: url('../assets/imgs/12.jpg');
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }
 
  .register_box {
    width: 260px;
    height: 290px;
    position: absolute;
    top: 0;
    left: 60%;
    right: 0;
    bottom: 0;
    margin: auto;
    padding: 40px 40px 40px 40px;
    box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);
    opacity: 1;
    background: linear-gradient(
      230deg,
      rgba(53, 57, 74, 0) 0%,
      rgb(0, 0, 0) 100%
    );
  }
 
  .inps input {
    border: none;
    color: #fff;
    background-color: transparent;
    font-size: 12px;
  }
 
  .submit {
    width: 200px;
  }
#link{
  font-family:"Helvetica Neue";
  color:rgb(151, 144, 144);
}
</style>